package com.cdtu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtu.entity.Resource;
import com.cdtu.service.ResourceService;
import com.cdtu.mapper.ResourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Sakura
* @description 针对表【resource】的数据库操作Service实现
* @createDate 2023-01-08 12:29:11
*/
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
    implements ResourceService{
    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public List<Resource> queryAll() {
        List<Resource> list = resourceMapper.queryAll();
        return list;
    }

    @Override
    public List<Resource> queryByCategory(String category) {
        return resourceMapper.queryResourceByCategory(category);
    }

    @Override
    public int deleteById(String id) {
        return resourceMapper.deleteResourceById(id);
    }

    @Override
    public int addResource(Resource resource) {
        return resourceMapper.saveResource(resource);
    }

    @Override
    public Resource findById(String id) {
        return resourceMapper.findResourceById(id);
    }

    @Override
    public Resource findByName(String name) {
        return resourceMapper.findResourceByName(name);
    }

    @Override
    public int addStockById(long id, int count) {
        return resourceMapper.addStockById(id,count);
    }

    @Override
    public boolean updateById(Resource resource) {
        int result = resourceMapper.updateById(resource);
        System.out.println(result);
        if (result==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Resource> findByPage(Integer pageNow, Integer rows) {
        int start=(pageNow-1)*rows;
        List<Resource> resourceList = resourceMapper.findByPage(start, rows);
        return resourceList;
    }

    @Override
    public long findTotal() {
        return resourceMapper.findTotal();
    }

    @Override
    public List<Resource> findResourceByPage(Integer pageNow, Integer rows, String category) {
        int start=(pageNow-1)*rows;
        List<Resource> resourceList = resourceMapper.findByCategoryPage(start, rows, category);
        return resourceList;

    }

    @Override
    public long findResourceTotal(String category) {
        return resourceMapper.findByCategoryTotal(category);
    }

    @Override
    public List<Resource> findByNamePage(Integer pageNow, Integer rows, String name) {
        int start=(pageNow-1)*rows;
        List<Resource> resourceList = resourceMapper.findByNamePage(start, pageNow, name);
        return resourceList;
    }

    @Override
    public long findByNameTotal(String name) {
        return resourceMapper.findByNameTotal(name);
    }
}




